package com.itzz.spring_zhoneHeng.service.Impl;

import com.itzz.spring_zhoneHeng.base.RestResponse;
import com.itzz.spring_zhoneHeng.dao.MemberDao;
import com.itzz.spring_zhoneHeng.pojo.Member;
import com.itzz.spring_zhoneHeng.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class MemberServiceImpl implements MemberService {

    @Autowired
    MemberDao memberDao;

    //根据uid回显数据
    @Override
    public RestResponse queryById(Integer uid) {
       Member member = memberDao.queryById(uid);

       return RestResponse.ok(member);
    }

    //修改会员和用户姓名数据
    @Override
    @Transactional
    public RestResponse edit(Integer mbid,Integer uid){
        //根据uid删除u_mb表数据
        memberDao.deleteU_MB(uid);
        //添加u_mb表数据  根据uid添加u_mb表数据
        int i = memberDao.addU_MB(mbid, uid);
        return RestResponse.ok(i);
    }


    //添加会员
    @Override
    public RestResponse add(Member member){
        member.setMbid(0);
        int i = memberDao.insert(member);
        return RestResponse.ok(i);
    }
}
